package com.wcs.exam.controller.admin;

import com.wcs.exam.common.base.Result;
import com.wcs.exam.common.base.annotation.OptLog;
import com.wcs.exam.common.base.annotation.OptLogCache;
import com.wcs.exam.controller.admin.biz.AdminSysMenuBiz;
import com.wcs.exam.controller.admin.req.*;
import com.wcs.exam.controller.admin.resp.AdminSysMenuListResp;
import com.wcs.exam.controller.admin.resp.AdminSysMenuViewResp;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Admin-菜单信息
 *
 * @author wcs
 * @since 2024-07-06
 */
@Tag(name = "Admin-菜单信息")
@RestController
@RequiredArgsConstructor
@RequestMapping("/v1/admin/sys/menu")
public class AdminSysMenuController {

    @NotNull
    private final AdminSysMenuBiz biz;

    /**
     * 菜单信息列出信息接口
     */
    @Operation(summary = "菜单列出")
    @GetMapping(value = "/list")
    public Result<List<AdminSysMenuListResp>> list(@ModelAttribute AdminSysMenuListReq req) {
        return biz.list(req);
    }

    @Operation(summary = "菜单信息-添加")
    @OptLog(value = "菜单信息添加")
    @PostMapping(value = "/save")
    public Result<String> save(@RequestBody @Valid AdminSysMenuSaveReq req) {
        return biz.save(req);
    }

    @Operation(summary = "菜单信息-查看")
    @Parameter(name = "id", description = "主键ID", required = true)
    @OptLogCache
    @GetMapping(value = "/view")
    public Result<AdminSysMenuViewResp> view(@RequestParam Long id) {
        return biz.view(id);
    }

    @Operation(summary = "菜单信息-编辑")
    @OptLog(value = "菜单信息编辑", isUpdate = true)
    @PutMapping(value = "/edit")
    public Result<String> edit(@RequestBody @Valid AdminSysMenuEditReq req) {
        return biz.edit(req);
    }

    @Operation(summary = "菜单信息-更新状态")
    @OptLog(value = "菜单信息更新状态")
    @PutMapping(value = "/update/status")
    public Result<String> updateStatus(@RequestBody @Valid AdminSysMenuUpdateStatusReq req) {
        return biz.updateStatus(req);
    }

    @Operation(summary = "菜单信息-排序")
    @OptLog(value = "菜单信息排序")
    @PutMapping(value = "/sort")
    public Result<String> sort(@RequestBody @Valid List<AdminSysMenuSortReq> reqs) {
        return biz.sort(reqs);
    }

    @Operation(summary = "菜单信息-删除")
    @Parameter(name = "id", description = "主键ID", required = true)
    @OptLog(value = "菜单信息删除")
    @DeleteMapping(value = "/delete")
    public Result<String> delete(@RequestParam Long id) {
        return biz.delete(id);
    }

}
